<style>
    a.detailcontiner span{
        display:none;
    }
    a.detailcontiner:hover span{
        display:initial;
    }
    a.updatecontiner span{
        display:none;
    }
    a.updatecontiner:hover span{
        display:initial;
    }
    a.changestatuscontiner span{
        display:none;
    }
    a.changestatuscontiner:hover span{
        display:initial;
    }
    a.orderedcontiner span{
        display:none;
    }
    a.orderedcontiner:hover span{
        display:initial;
    }
</style>
<div class="layui-fluid layui-anim febs-anim" id="businesses-video" lay-title="在线课程">
    <div class="layui-row febs-container">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body febs-table-full">
                    <form class="layui-form layui-table-form" lay-filter="college-table-form" id="vido_From">
                        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 10px;">
                            <legend style="font-size: 15px; font-weight: bolder;">批量查询</legend>
                        </fieldset>
                        <div class="layui-row">
                            <div class="layui-col-md10">
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">名称</label>
                                        <div class="layui-input-inline search-video">
                                            <input type="text" name="name" autocomplete="off" class="layui-input" id="nameVideo">
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">分类</label>
                                        <div class="layui-input-block" id="video-search-type"
                                             style="width: 150px;">
                                            <input type="hidden" id="typeNameVideo" name="typeName" autocomplete="off"
                                                   class="layui-input">
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">编辑人</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="updateName" id="cboUpdateNameVideo"
                                                   class="layui-input">
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-col-md2 table-action-area">
                                <div class="layui-btn layui-btn-sm layui-btn-primary febs-button-blue-plain  table-action" id="queryVideo" >
                                    <i class="layui-icon">&#xe848;</i>
                                </div>
                                <div class="layui-btn layui-btn-sm layui-btn-primary febs-button-green-plain  table-action" id="resetVideo">
                                    <i class="layui-icon">&#xe79b;</i>
                                </div>
                            </div>
                        </div>

                        <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">

                            <div class="layui-row">


                                <div class="layui-btn layui-btn-sm layui-btn-primary febs-button-blue-plain table-action" id="addvideo">
                                    <i class="layui-icon layui-icon-plus-circle">新建视频</i>
                                </div>
                            </div>
                            <!--                            <div style="margin:10px;">-->

                            <!--                            </div>-->
                        </blockquote>
                    </form>
                    <table lay-filter="videoTable" lay-data="{id: 'videoTable'}"></table>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/html" id="video-status">
    {{#
    let status = {
    1: {title: '上架', color: 'green'},
    0: {title: '下架', color: 'volcano'}
    }[d.status];
    }}
    <span class="layui-badge febs-bg-{{status.color}}">{{ status.title }}</span>
</script>
<script type="text/html" id="video-option">
    {{# if(d.status==0){}}
    <a lay-event="detail" class="detailcontiner"><i class="layui-icon febs-edit-area febs-green">&#xe7a5;</i><span>详情</span></a>
    <a lay-event="update" class="updatecontiner"><i
            class="layui-icon febs-edit-area febs-green">&#xe7a4;</i><span>编辑</span></a>
    <a lay-event="changestatus" class="changestatuscontiner">
        <i class="layui-icon febs-edit-area febs-blue">&#xe619;</i><span>上架</span></a>
    <a lay-event="ordered" class="orderedcontiner"><i class="layui-icon febs-edit-area febs-red">&#xe649;</i><span>排序</span></a>
    {{# } else if(d.status==1) {}}
    <a lay-event="detail" class="detailcontiner"><i class="layui-icon febs-edit-area febs-green">&#xe7a5;</i><span>详情</span></a>
    <a lay-event="update" class="updatecontiner"><i
            class="layui-icon febs-edit-area febs-green">&#xe7a4;</i><span>编辑</span></a>
    <a lay-event="changestatus" class="changestatuscontiner">
        <i class="layui-icon febs-edit-area febs-blue">&#xe61a;</i><span>下架</span></a>
    <a lay-event="ordered" class="orderedcontiner"><i class="layui-icon febs-edit-area febs-red">&#xe649;</i><span>排序</span></a>
    {{# } else {}}
    {{# } }}
</script>
<script type="text/javascript" src="module/treeSelect/treeSelect.js"></script>
<script data-th-inline="none" type="text/javascript">

    layui.use(['dropdown', 'jquery', 'form', 'table', 'febs','layer', 'xmSelect','treeSelect'], function () {
        let $ = layui.jquery,
            febs = layui.febs,
            form = layui.form,
            table = layui.table,
            dropdown = layui.dropdown,
            $view = $('#businesses-video'),
            $query = $view.find('#queryVideo'),
            $reset = $view.find('#resetVideo'),
            $addvideo=$view.find('#addvideo'),
            $searchForm = $view.find('form'),
            sortObject = {field: 'createDate', type: null},
            layer = layui.layer,
            xmSelect = layui.xmSelect,
            treeSelect = layui.treeSelect,
            typeXmSelect,
            updateNameXmSelect,
            tableIns;

        form.render();

        typeXmSelect = xmSelect.render({
            el: '#video-search-type',
            model: {label: {type: 'text'}},
            radio:true,
            clickClose: true,
            tips:'请选择课程分类',
            tree: {
                show: true,
                strict: false,
                showLine: true,
                clickCheck: true,
                expandedKeys: true,
            },
            name: 'typeId',
            theme: {
                color: '#52c41a',
            },
            prop: {
                value: 'id'
            },
            height: '500px',
            on: function (data) {
                console.log("video的分类树：");
                console.log(data);
                if(data.isAdd){
                    $("#typeNameVideo").val(data.change[0].name);
                }else {
                    $("#typeNameVideo").val("");
                }
                let params = $.extend(getQueryParams(), {field: sortObject.field, order: sortObject.type});
                tableIns.reload({where: params, page: {curr: 1}});
            }
        });
        febs.get(ctx + 'cType/select/treexk', null, function (data) {
            typeXmSelect.update(data);
        });

        //构建编辑人树结构
        treeSelect.render({
            // 选择器
            elem: '#cboUpdateNameVideo',
            // 数据
            data: ctx + 'student/selectStudentuserDeptTree',
            // 异步加载方式：get/post，默认get
            type: 'get',
            // 占位符
            placeholder: '请选择编辑人',
            // 是否开启搜索功能：true/false，默认false
            search: true,
            style: {
                folder: { // 父节点图标
                    enable: true // 是否开启：true/false
                },
                line: {
                    enable: true
                }
            },
            // 点击回调
            click: function (d) {
                console.log("编辑人树结构：");
                console.log(d);
                $("#cboUpdateNameVideo").val(d.current.name);
                let params = $.extend(getQueryParams(), {field: sortObject.field, order: sortObject.type});
                tableIns.reload({where: params, page: {curr: 1}});
            },
            // 加载完成后的回调函数
            success: function (d) {
                console.log(d);
            }
        });

        initTable();
        //新建视频
        $addvideo.on('click',function () {
            febs.modal.open('新建视频','video/add',{
                btn: ['保存并发布', '保存草稿','重置'],
                area: $(window).width() <= 750 ? '95%' : '50%',
                yes: function (index, layero) {
                    $('#video-add').find('#submitVideo1').trigger('click');
                    // 单击之后提交按钮不可选,防止重复提交
                    var DISABLED = 'layui-btn-disabled';
                    // 增加样式
                    $('#video-add').find('#submitVideo1').addClass(DISABLED);
                    // 增加属性
                    $('#video-add').find('#submitVideo1').attr('disabled', 'disabled');
                    setTimeout(function () {
                        $('#video-add').find('#submitVideo1').removeClass(DISABLED).attr('disabled', false);
                    },2000);
                    return false;
                },
                btn2: function () {
                    $('#video-add').find('#submitVideo0').trigger('click');
                    // 单击之后提交按钮不可选,防止重复提交
                    var DISABLED = 'layui-btn-disabled';
                    // 增加样式
                    $('#video-add').find('#submitVideo0').addClass(DISABLED);
                    // 增加属性
                    $('#video-add').find('#submitVideo0').attr('disabled', 'disabled');
                    setTimeout(function () {
                        $('#video-add').find('#submitVideo0').removeClass(DISABLED).attr('disabled', false);
                    },2000);
                    return false;
                },
                btn3: function () {
                    $('#video-add').find('#resetVideo').trigger('click');
                    return false;
                },
            });
        });
        table.on('tool(videoTable)', function (obj) {
            let data = obj.data,
                layEvent = obj.event;
            if (layEvent === 'detail') {
                febs.modal.view('查看课程详情', 'video/detail/' + data.id, {
                    area: $(window).width() <= 750 ? '95%' : '660px',
                    btn: ['确定'],
                    yes: function (index, layero) {
                        layer.closeAll();
                    }
                });
            }
            if (layEvent === 'changestatus') {
              if(data.status==0){
                  febs.modal.confirm('上架', '确定上架吗？', function () {
                      $.ajax({
                          type:'get',
                          url:'/video/updateByIdSatusUp?id='+data.id,
                          success:function () {
                              //刷新表单
                              table.reload("videoTable", {url:'/video/list'})
                              //关闭提示框
                              febs.modal.close(index)
                          }
                      })
                  });

              }else if(data.status==1) {
                  febs.modal.confirm('下架', '确定下架吗？', function () {
                      $.ajax({
                          type: 'get',
                          url: '/video/updateByIdSatus?id=' + data.id,
                          success: function () {
                              console.log("465")
                              //刷新表单
                              table.reload("videoTable", {url: '/video/list'})
                              //关闭提示框
                              febs.modal.close(index)
                          }
                      })
                  });
              }
            }
            if (layEvent === 'ordered') {
                febs.modal.open('排序', 'video/updateSort/'+data.id, {
                    area: $(window).width() <= 750 ? '90%' : '30%',
                    btn: ['确定', '取消'],
                    yes: function (index, layero) {
                        $('#video-sort').find('#submitVideoSort').trigger('click');
                        // 单击之后提交按钮不可选,防止重复提交
                        var DISABLED = 'layui-btn-disabled';
                        // 增加样式
                        $('#video-sort').find('#submitVideoSort').addClass(DISABLED);
                        // 增加属性
                        $('#video-sort').find('#submitVideoSort').attr('disabled', 'disabled');
                        setTimeout(function () {
                            $('#video-sort').find('#submitVideoSort').removeClass(DISABLED).attr('disabled', false);
                        },2000);
                    },
                    btn2: function () {
                        layer.closeAll();
                    }
                });
            }
            if (layEvent === 'update') {
                febs.modal.open('编辑课程', 'video/update/' + data.id, {
                    area: $(window).width() <= 750 ? '90%' : '50%',
                    btn: ['确定', '取消'],
                    yes: function (index, layero) {
                        $('#video-update').find('#submitVideo').trigger('click');
                    },
                    btn2: function () {
                        layer.closeAll();
                    }
                });
            }
        });
        /*
        table.on('sort(videoTable)', function (obj) {
            sortObject = obj;
            tableIns.reload({
                initSort: obj,
                where: $.extend(getQueryParams(), {
                    field: obj.field,
                    order: obj.type
                })
            });
        });
        */

        function initTable() {
            tableIns = febs.table.init({
                elem: $view.find('table'),
                id: 'videoTable',
                url: ctx + 'video/list',
                cols: [[
                    {field: 'id', title: '编号',minWidth: 50,type:'checkbox'},
                    {field: 'sort', title: '序号',minWidth: 50},
                    {
                        field:'imgUrl',
                        title:'封面',
                        minWidth: 100,
                        templet:'<div><a href="{{ d.imgUrl }}"><img style="width: 80px;height: 40px;vertical-align: middle" src="{{ d.imgUrl }}"></a></div>'
                     },
                    /*
                    {
                        field:'videoUrl',
                        title:'视频',
                        minWidth: 100,
                        templet:'<div><a href="{{ d.videoUrl }}"><video style="width: 80px;height: 40px;vertical-align: middle" src="{{ d.videoUrl }}"></a></div>'
                    },
                    */
                    {field: 'name', title: '名称', minWidth: 150},
                    {field: 'info', title: '简介', minWidth: 165},
                    {field: 'typeName', title: '分类', minWidth: 180},
                    /*
                    {field: 'createTime', title: '上架时间', minWidth: 120},
                    */
                    {field: 'updateTime', title: '操作时间', minWidth: 120},
                    {field: 'status', title: '状态', templet:'#video-status',minWidth: 70},
                    {field: 'updateName', title: '操作人', minWidth: 80},
                    {title: '操作', toolbar: '#video-option', minWidth: 170}
                ]]
            });
        }

        /*
        function deleteColleges(collegeIds) {
            febs.get(ctx + 'video/updateByIdSatus/' + collegeIds, null, function () {
                febs.alert.success('改变状态成功');
                $query.click();
            });
        }
        */
        function getQueryParams(flag) {
            let params =$searchForm.serializeJson();
            return params;
        }
        $reset.on('click', function () {
            $searchForm[0].reset();
            tableIns.reload({where: getQueryParams(true), page: {curr: 1}, initSort: sortObject});
        });
        $query.on('click', function () {
            let params = $.extend(getQueryParams(), {field: sortObject.field, order: sortObject.type});
            tableIns.reload({where: params, page: {curr: 1}});
        });
        //按回车搜索
        $(".search-video").keydown(function (e) {//当按下按键时
            if (e.which == 13) {//.which属性判断按下的是哪个键，回车键的键位序号为13
                $query.click();
            }
        });
    })

</script>